package cn.yyt.yytravel.inform.service;

import cn.yyt.yytravel.guide.mapper.GuideMapper;
import cn.yyt.yytravel.inform.mapper.InformMapper;
import cn.yyt.yytravel.inform.pojo.dto.InformQuery;
import cn.yyt.yytravel.inform.pojo.dto.InformSaveParam;
import cn.yyt.yytravel.inform.pojo.entity.Inform;
import cn.yyt.yytravel.inform.pojo.vo.InformVO;
import cn.yyt.yytravel.user.mapper.UserMapper;
import cn.yyt.yytravel.user.pojo.entity.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class InformServiceImpl implements InformService{
    @Autowired
    InformMapper informMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    GuideMapper guideMapper;
    @Override
    public void insert(InformSaveParam informSaveParam) {
        Inform inform = new Inform();
        BeanUtils.copyProperties(informSaveParam,inform);
        inform.setStatus(20);
        informMapper.insert(inform);
    }

    @Override
    public List<InformVO> select(InformQuery informQuery) {
        List<Inform> list = informMapper.selectInform(informQuery);
        List<InformVO> list2 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            InformVO informVO = new InformVO();
            BeanUtils.copyProperties(list.get(i),informVO);
            System.out.println("informVO" + informVO);
            informVO.setGuideName(userMapper.selectById(list.get(i).getGuideId()).getUsername());
            System.out.println(informVO);
            list2.add(informVO);
        }
        System.out.println("----"+list2);
        return list2;
    }

    @Override
    public void delete(Integer id) {
        informMapper.delete(id);
    }

}
